package com.wangxq.yd_base.app;

//import com.alibaba.android.arouter.launcher.ARouter;
import android.text.TextUtils;
import android.util.Log;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.CacheDiskUtils;
import com.blankj.utilcode.util.Utils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jess.arms.base.BaseApplication;
import com.jess.arms.database.MMkvHelper;
import com.jess.arms.integration.IRepositoryManager;
import com.orhanobut.logger.Logger;
import com.tencent.mmkv.MMKV;
import com.wangxq.yd_base.R;
import com.zlx.module_base.base_util.YdBase;

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * copyright (C), 2021, 运达科技有限公司
 * fileName App
 *
 * @author 王玺权
 * date 2021-10-13 11:51
 * description
 * history
 */
public class App extends BaseApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        //腾讯序列化
        MMKV.initialize(this);
//        ARouter.openLog();
//        ARouter.openDebug();
//        ARouter.init(this);
        Utils.init(this);
        resetConfig();
    }
    private void resetConfig(){
        String saveBaseUrl = "http://192.168.1.133:8090";
        String baseUrl= TextUtils.isEmpty(saveBaseUrl)?"http://192.168.1.133:8090":saveBaseUrl;
        YdBase.INSTANCE
                //设置登录成功后跳转页面
                .setMainUrl("com.wangxq.sh17_mvp.module.home.mvp.ui.activity.HomeActivity")
                //设置服务器地址
                .setBaseUrl(baseUrl)
                //设置webSocket
                .setWebsocketUrl("http://139.9.246.226:8081")
                //设置登录接口
                .setLoginUrl("/DTCG/app/appLogin.action")
                //设置服务名
                .setServiceName("DTCG")
                //设置登录页面展示版本号
                .setAppVersion("v"+ AppUtils.getAppVersionName())
                //设置登录页面开发公司
                .setCompanyName("运达科技有限公司")
                .setAppName("车辆维修执行系统")
                .setAppLogo(R.mipmap.logo)
                .setWebSocketVisible(false)
                .setCompulsiveUpdate(false)
                .setAppUpdateUrl("kmjx/pdaAppUpdate/pda_sb_version.xml")
                .setOffLineMode(true)
                .init();

        Log.e("initBaseUrl",baseUrl);
        OkHttpClient okHttpClient = getAppComponent().okHttpClient();
        HttpUrl apiUrl = getAppComponent().httpUrl();
        IRepositoryManager iRepositoryManager = getAppComponent().repositoryManager();
        apiUrl = HttpUrl.parse(baseUrl);
        Gson gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
                .serializeNulls()
                .create();
        iRepositoryManager.setRetrofit(new Retrofit.Builder().baseUrl(apiUrl).client(okHttpClient)
                .addConverterFactory(ScalarsConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create(gson)).build());
    }
}
